localStorage.setItem('_role', '0');
const vm = new Vue({
    el: '#tab-nav',
    data: {
        ROLE: localStorage.getItem('_role'),
        tab1: true,
        tab2: false,
        tab3: false,
        tab4: false,
        current: 'tab1',
    },
    methods: {
        openF,
    },
});

if (fxj.deBug) {
    main()
}

function apiready() {
    main()
    openFindHtml();
}

async function main() {
    const token = localStorage.getItem('token');
    if (token) {
        const res = await ajax({
            url: 'home/index/checkToken',
            data: {
                token,
            },
        });
        if (res.err === 1) {
            localStorage.removeItem('token');
        }
    }
}

function openFindHtml() {
    switchRole();
    openF('html/find.html', 1);
}

function openF(html, i) {
    if (i > 1 && !localStorage.getItem('token')) {
        openWin({
            url: 'html/log_in.html',
        });
        return;
    }
    vm[vm.current] = false;
    vm[`tab${i}`] = true;
    vm.current = `tab${i}`;
    let y = 0;
    let h = document.body.offsetHeight - document.getElementById('tab-nav').offsetHeight;
    if (apiOk()) {
        openFrame({
            url: html,
            bounces: true,
            rect: {
                x: 0,
                y,
                w: 'auto',
                h,
            },
        });
    } else {
        location.assign(html);
    }
}

// noinspection JSUnusedGlobalSymbols
function openIndent() {
    api.execScript({
        frameName: 'indent',
        script: 'reqOrderList(1)',
    });
    openF('html/indent.html', 2);
}

function switchRole() {
    vm.ROLE = localStorage.getItem('_role');
    vm.$forceUpdate();
}